package com.lagou.edu.service.impl;

import com.lagou.edu.service.IEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author stevejson
 */
@Service
@Slf4j
public class EmailServiceImpl implements IEmailService {
    @Value("${spring.mail.username}")
    private String from;

    @Resource
    private JavaMailSender sender;

    @Override
    public void sendSimple(String to, String title, String content) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(to);
        message.setSubject(title);
        message.setText(content);
        sender.send(message);
        System.out.println("邮件发送成功");
    }
}
